package com.why.configurebean;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 每个Mapper(Dao)和一个MapperStatement对应
 *
 * @author wanghongyang24
 */
public class DefaultConfiguration {
    private static final Logger logger = LoggerFactory.getLogger(DefaultConfiguration.class);
    private SormProperties properties;
    /*
     *每个Mapper(Dao)和一个MapperStatement对应
      key:全类名+方法名;value.每个类有其对应的各种sql语句
     */
    private Map<String, MapperStatement> classMappingMapper;


    public SormProperties getProperties() {
        return properties;
    }

    public Map<String, MapperStatement> getClassMappingMapper() {
        return classMappingMapper;
    }

    public DefaultConfiguration() {
    }

    public DefaultConfiguration(SormProperties properties) {
        this.properties = properties;
        this.classMappingMapper = new HashMap<>(128);

    }

    public void addMapper(MapperStatement statement) {
        logger.info("成功添加一个statement");
        if (classMappingMapper.containsKey(statement.getId())) {
            throw new IllegalArgumentException("多个相同的mapperId被发现");
        }
        classMappingMapper.put(statement.getId(), statement);
    }


}
